package com.gucheng.ggbi.bizmq;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;

@Component
@Slf4j
public class BiMessageProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送消息
     *
     * @param message
     */
    public void sendMessage(String message) {
        try {
            rabbitTemplate.convertAndSend(BiMqConstant.BI_EXCHANGE_NAME, BiMqConstant.BI_ROUTING_KEY, message);
            log.info("Sent message: {}", message);
        } catch (Exception e) {
            log.error("Error sending message", e);
        }
    }

    /**
     * 发送消息到死信队列
     *
     * @param message
     */
    public void sendToDeadLetterQueue(String message) {
        try {
            rabbitTemplate.convertAndSend(DeadLetterQueueConfig.BI_DEAD_LETTER_EXCHANGE_NAME, "bi_dead_routing_key", message);
            log.info("Sent message to dead letter queue: {}", message);
        } catch (Exception e) {
            log.error("Error sending message to dead letter queue", e);
        }
    }
}